import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../utils/constant.dart';

class MyAppBar extends AppBar {
  final GlobalKey<NavigatorState> navigatorKey =
      new GlobalKey<NavigatorState>();

  MyAppBar(
      {required BuildContext context,
      title,
      hasLeading = false,
      popWithParam,
      showSearch = false,
      showFilter = false,
      callBack = Function})
      : super(
            bottom: PreferredSize(
                child: Container(
                  color: Color(0xFFDDDDDD),
                  width: double.infinity,
                  height: 0.5,
                ),
                preferredSize: Size.fromHeight(0)),
            title: Text(
              title,
              style: TextStyle(color: Color(0xFF3C4353), fontSize: 18.sp),
            ),
            leading: hasLeading == false
                ? Text('')
                : IconButton(
                    icon: Container(
                      padding: EdgeInsets.all(3.0),
                      child: Image.asset(
                        Constant.IMG_BASE + 'ic_back.png',
                        width: 15.w,
                        height: 15.h,
                      ),
                    ),
                    onPressed: () {
                      if (popWithParam != null && popWithParam == true) {
                        print('1212');
                        Navigator.of(context).pop('11');
                      } else {
                        print('3333');
                        Navigator.of(context).pop();
                      }
                    },
                  ),
            actions: <Widget>[
              showSearch
                  ? InkWell(
                      onTap: () {
                        callBack('search');
                      },
                      child: Container(
                          margin: EdgeInsets.only(right: 30.w),
                          child: Image.asset(
                            Constant.IMG_BASE + 'icon_search.png',
                            width: 16.w,
                            height: 16.h,
                          )))
                  : Container(),
              showFilter
                  ? InkWell(
                      onTap: () {
                        callBack('filter');
                      },
                      child: Container(
                          margin: EdgeInsets.only(right: 25.w),
                          child: Image.asset(
                            Constant.IMG_BASE + 'icon_filter.png',
                            width: 17.w,
                            height: 16.h,
                          )))
                  : Container()
            ],
            elevation: 0,
            backgroundColor: Colors.white,
            centerTitle: true);
}
